package healthyPointsManager.pojo
{
	import mx.controls.DateField;	
	
	public class FavoriteFood
	{		
		private var _id:Number=0;
		private var _name:String;
		private var _calories:Number;
		private var _fat:Number;
		private var _fiber:Number;
		private var _points:Number;
		private var _servingSize:Number;
		private var _isFavorites:Boolean;
		private var _mealTime:String;
		private var _isQuickAdd:Boolean;
		private var _dateCreated:Date;//original date of food being created
		private var _dateModified:Date;//date of late time food was used/changed etc
		private var _createdBy:String;//user who originally created the food item
		private var _type:String;//type of food, such as food, receipe... or maybe thermal nuclear device... but probably not.
				
		public function FavoriteFood(){
						
		}
		
		/*This is a function that takes back a generic JSON like object with data that makes up a Favorite food object and converts it into such.*/
		public static function createFavoriteFood(value:Object):FavoriteFood{			
			var returnValue:FavoriteFood = new FavoriteFood();
			if(value != null ){
				returnValue.id = isNaN(value.id) ? 0 : value.id;
				returnValue.isQuickAdd = returnValue.id == 0 ? true : false;
//				returnValue.isQuickAdd = isNaN(value.quickAddId) ? 0 : value.quickAddId;
				if(!returnValue.isQuickAdd){//only add the following information if the food isn't a quick add.
					returnValue.calories = value.calories;
					returnValue.fat = value.fat;
					returnValue.fiber = value.fiber;				
					returnValue.servingSize = value.servingSize;
					returnValue.isFavorites = value.foodFavServingSize > 0 ? true : false;//is favorites is measure by their being a foodFavServingSize > 0
					returnValue.createdBy = value.createdBy;			
					returnValue.dateCreated = value.dateCreate != null ? DateField.stringToDate(value.dateCreated, "YYYY-MM-DD") : null;//might be an issue if this is ever null
					returnValue.dateModified = value.dateModified != null ? DateField.stringToDate(value.dateModified, "YYYY-MM-DD") : null;
					returnValue.type = value.type;	
				}
				returnValue.name = value.name;
				returnValue.points = value.points;				
				returnValue.mealTime = value.mealTime;				
				
			}		
			return returnValue;				
		}	
		
		public function get id():Number{
			return _id;
		}
		
		public function set id(value:Number):void{
			_id = value;
		}
		
		[Bindable]		
		public function get name():String{
			return _name;
		}
		
		public function set name(value:String):void{
			_name = value;
		}
		
		public function get calories():Number{
			return _calories;
		}
		
		public function set calories(value:Number):void{
			_calories = value;
		}
		
		public function get fat():Number{
			return _fat;
		}
		
		public function set fat(value:Number):void{
			_fat = value;
		}
		
		public function get fiber():Number{
			return _fiber;
		}
		
		public function set fiber(value:Number):void{
			_fiber = value;
		}
		
		public function get points():Number{
			return _points;
		}
		
		public function set points(value:Number):void{
			_points = value;
		}
		
		public function get servingSize():Number{
			return _servingSize;
		}
		
		public function set servingSize(value:Number):void{
			_servingSize = value;
		}
		
		[Bindable]
		public function get isFavorites():Boolean{
			return _isFavorites;
		}
		
		public function set isFavorites(value:Boolean):void{
			_isFavorites = value;
		}
		
		public function get mealTime():String{
			return _mealTime;
		}
		//This mealTime is supposed to match up to the labels of the arrayCollection timeOfDay found in Constants.as
		public function set mealTime(value:String):void{
			_mealTime = value;
		}
		
		
		public function get isQuickAdd():Boolean{
			return _isQuickAdd;
		}
		
		public function set isQuickAdd(value:Boolean):void{
			_isQuickAdd = value;
		}
		
		public function get dateCreated():Date{
			return _dateCreated;
		}		
		
		public function set dateCreated(value:Date):void{
			_dateCreated = value;
		}
		
		public function get dateModified():Date{
			return _dateModified;
		}		
		
		public function set dateModified(value:Date):void{
			_dateModified = value;
		}
		
		public function get createdBy():String{
			return _createdBy;
		}
		
		public function set createdBy(value:String):void{
			_createdBy = value;
		}
		
		public function get type():String{
			return _type;
		}
		
		public function set type(value:String):void{
			_type = value;
		}
		
		/*This is a flex specific helper function.  This forces flex to make a new object rather than simply updating a bindable object.  This of often called with
		UI maniuplation because usually copying object A via the UI will appear to create an object B but modifying object B will also update object A.  This deep
		copy allows object be to exist and be modified independantly of the object A it might have once been copied from.*/
		public function deepCopyFavoriteFood(value:FavoriteFood):FavoriteFood{
			var returnValue:FavoriteFood = new FavoriteFood();
			if(value != null ){
				returnValue.id = value.id;				
				returnValue.calories = value.calories;
				returnValue.fat = value.fat;
				returnValue.fiber = value.fiber;
				returnValue.name = value.name;
				returnValue.points = value.points;
				returnValue.servingSize = value.servingSize;
				returnValue.isFavorites = value.isFavorites;
				returnValue.mealTime = value.mealTime;
				returnValue.isQuickAdd = value.isQuickAdd;
				//@returnValue.quickAddId = value.quickAddId;
				returnValue.createdBy = value.createdBy;
				returnValue.dateCreated = value.dateCreated;
				returnValue.dateModified = value.dateModified;
				returnValue.type = value.type;//all 14 properties are copied
			}		
			return returnValue;				
		}
		
		/*Custom to array function that stores each private member variable into an array in a particular order*/
		public function toHttpObject(userName:String, foodType:String):Object{			
			type = foodType;
			createdBy = userName;			
			return this;
		}
		
		public function toArray():Array{
			var array:Array = new Array(14);
			array[0] = this.id;
			array[1] = this.calories;
			array[2] = this.fat;
			array[3] = this.fiber;
			array[4] = this.name;
			array[5] = this.points;
			array[6] = this.servingSize;
			array[7] = this.isFavorites;
			array[8] = this.mealTime;
			array[9] = this.isQuickAdd;
			array[10] = this.createdBy;
			array[11] = this.dateCreated;
			array[12] = this.dateModified;
			array[13] = this.type;
			return array;
		}
	}
}